def show_lines(file_load):
    num_count = 1
    with open(f'{file_load}', 'r', encoding='utf-8') as file:
        file_lines = file.readlines()
        for file_line in file_lines:
            print(f'{num_count}.' + file_line)
            num_count += 1
        file.close()
        return file_lines


while True:
    print('选择你的操作:')
    print('1.添加\n2.删除\n3.修改\n4.查询\n5.退出')
    choice = input('请输入您的选择:')
    if choice == '1':
        todo = input('请输入您的待办事项:')
        with open('待办事项.txt', 'a', encoding='utf-8') as f:
            f.write(todo + '\n')
        f.close()

    elif choice == '2':
        lines = show_lines('待办事项.txt')
        print('删除段落（填写序列号）')
        n = input('请输入您的选择:')
        lines.pop(int(n) - 1)
        with open('待办事项.txt', 'w', encoding='utf-8') as f:
            f.writelines(lines)
            f.close()

    elif choice == '3':
        lines = show_lines('待办事项.txt')
        print('修改段落（填写序列号）')
        n = input('请输入您的选择:')
        lines[int(n) - 1] = input('请输入修改后的内容:') + '\n'
        with open('待办事项.txt', 'w', encoding='utf-8') as f:
            f.writelines(lines)
            f.close()

    elif choice == '4':
        show_lines('待办事项.txt')

    elif choice == '5':
        print('退出成功')
        break

    else:
        print('输入错误，请重新输入')
        continue
